package com.example.ruihuada.ui.HomeModule.adapter

import android.content.Context
import android.widget.ImageView
import android.widget.LinearLayout
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.example.ruihuada.R


class ShopDetailsAdapter(data: List<String>) :
    BaseQuickAdapter<String, BaseViewHolder>(R.layout.shop_detail_list_item, data) {
    override fun convert(helper: BaseViewHolder, item: String?) {
        val contentPanel = helper.getView<LinearLayout>(R.id.contentPanel)
        val width = (mContext.resources.displayMetrics.widthPixels - mContext.dp2px(40 + 15)) / 2
        contentPanel.layoutParams.width = width
        val profileIv = helper.getView<ImageView>(R.id.im_item_bg)
        profileIv.layoutParams.width = width
        profileIv.layoutParams.height = width
        helper.setText(R.id.tv_title, item)
    }

    fun Context?.dp2px(dp: Int): Int {
        if (this == null) {
            return 0
        }
        val scale = resources.displayMetrics.density
        return (dp * scale + 0.5f).toInt()
    }


}